<script setup>
import SltFromOthApi from '@/components/SltFromOthApi/SltFromOthApi.vue'
import { PlusOutlined, SearchOutlined, RedoOutlined } from '@ant-design/icons-vue'
import { ref } from 'vue'

const emits = defineEmits(['add', 'init', 'search'])
// 新增按钮点击
const add = () => {
  emits('add')
}
// 刷新
const orderNo = ref('')
const machineId = ref(null)
const init = () => {
  orderNo.value = ''
  machineId.value = null
  emits('init')
}
// 搜索
const search = () => {
  emits('search', {
    orderNo: orderNo.value ?? null,
    machineId: machineId.value?.[machineId?.value?.length - 1] || null
  })
}
</script>

<template>
  <div class="head">
    <AButton type="primary" @click="add"> <PlusOutlined /> 新增 </AButton>
    <div class="right">
      <a-input
        @input="search"
        v-model:value="orderNo"
        placeholder="请输入工单编号查询"
        class="com-ipt"
        allowClear
      >
        <template #suffix>
          <SearchOutlined />
        </template>
      </a-input>
      <SltFromOthApi
        @change="search"
        :fieldNames="{ label: 'machineName', value: 'machineId', children: 'children' }"
        v-model="machineId"
        placeholder="请选择农机查询"
        :dataProp="['data', 'records']"
        apiName="getMachinList"
        class="com-ipt"
        :params="{ size: 9999 }"
      />
      <AButton type="primary" @click="search"> <SearchOutlined /> 搜索 </AButton>
      <AButton type="primary" @click="init"> <RedoOutlined /> 刷新 </AButton>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.head {
  display: flex;
  gap: 8px;
  justify-content: space-between;

  .right {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }
}
</style>